//
//  CommendListenCollectionViewCell.m
//  MountEverestFM
//
//  Created by ChenNing on 15/11/2.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "CommendListenCollectionViewCell.h"

@interface CommendListenCollectionViewCell()
// 标题背景
@property(nonatomic,strong)UIImageView *titleBgImageView;
// 标题
@property(nonatomic,strong)UILabel *titleLabel;
// 内容
@property(nonatomic,strong)UILabel *contentLabel;
// 曲目图的头装饰
@property(nonatomic,strong)UIImageView *imageButtonHeader;
@end

@implementation CommendListenCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageButtonHeader = [[UIImageView alloc] init];
        [self.contentView addSubview:_imageButtonHeader];
        
        self.imageButton = [[UIButton alloc] init];
        [self.contentView addSubview:_imageButton];
        
        self.titleBgImageView = [[UIImageView alloc] init];
        [self.imageButton addSubview:_titleBgImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = [UIColor whiteColor];
        self.titleLabel.font = [UIFont systemFontOfSize:11];
        [self.titleBgImageView addSubview:_titleLabel];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.font = [UIFont systemFontOfSize:13];
        self.contentLabel.numberOfLines = 0;
        [self.contentLabel sizeToFit];
        [self.contentView addSubview:_contentLabel];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.imageButtonHeader.frame = CGRectMake(0, 0, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3, FM_Screen_Pts_Height*7);
    
    self.imageButton.frame = CGRectMake(0, FM_Screen_Pts_Height*7, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3);
    self.titleBgImageView.frame = CGRectMake(0, self.imageButton.frame.size.height-FM_Screen_Pts_Height*20, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3, FM_Screen_Pts_Height*20);
    self.titleLabel.frame = CGRectMake(FM_Screen_Pts_Width*5, 0, self.titleBgImageView.frame.size.width-FM_Screen_Pts_Width*10, self.titleBgImageView.frame.size.height);
}

- (void)setCommDictionary:(NSDictionary *)commDictionary
{
    if (_commDictionary != commDictionary) {
        _commDictionary = commDictionary;
    }
    [self setCommendInfo:commDictionary];
}

- (void)setCommendInfo:(NSDictionary *)commDictionary
{
    self.imageButtonHeader.image = [UIImage imageNamed:@"find_albumtop@2x.png"];
    
    NSURL *imageUrl = [NSURL URLWithString:[commDictionary objectForKey:@"coverLarge"]];
    [self.imageButton sd_setBackgroundImageWithURL:imageUrl forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    
    
    self.titleBgImageView.image = [UIImage imageNamed:@"find_cover@2x.png"];
    self.titleLabel.text = [commDictionary objectForKey:@"title"];
    
    NSString *contentStr = [commDictionary objectForKey:@"trackTitle"];
    CGRect contentRect = [contentStr boundingRectWithSize:CGSizeMake((FM_Screen_Width-FM_Screen_Pts_Width*40)/3, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil];
    self.contentLabel.frame = CGRectMake(0, self.imageButton.frame.origin.y+(FM_Screen_Width-FM_Screen_Pts_Width*40)/3+FM_Screen_Pts_Height*5, (FM_Screen_Width-FM_Screen_Pts_Width*40)/3, contentRect.size.height);

    self.contentLabel.text = contentStr;
}
@end
